package strongholdCraft.common.Items;

import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import strongholdCraft.common.EntityPotionMilkSplash;
import strongholdCraft.common.mod_StrongholdCraft;

import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityPotion;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionHelper;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.Icon;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ItemPotionMilk extends Item{

//	public ItemPotionMilk(int id) {
//		super(id);
//		this.setCreativeTab(Items.tabEnd);
//
//	}


	
	
	
	
	
	
	    /** maps potion damage values to lists of effect names */

	    @SideOnly(Side.CLIENT)
	    private Icon field_94591_c;
	    @SideOnly(Side.CLIENT)
	    private Icon field_94590_d;
	    @SideOnly(Side.CLIENT)
	    private Icon field_94592_ct;

	    public ItemPotionMilk(int par1)
	    {
	        super(par1);
	        this.setMaxStackSize(1);
	        this.setHasSubtypes(false);
	        this.setMaxDamage(0);
	    }

	    /**
	     * Returns a list of potion effects for the specified itemstack.
	     */

	        
	    /**
	     * Returns a list of effects for the specified potion damage value.
	     */
	   

		public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
	    {
	        if (!par3EntityPlayer.capabilities.isCreativeMode)
	        {
	            --par1ItemStack.stackSize;
	        }
	
	        if (!par2World.isRemote)
	        {
	        	par3EntityPlayer.curePotionEffects(new ItemStack(Item.bucketMilk, 1));
	        }
	
	        if (!par3EntityPlayer.capabilities.isCreativeMode)
	        {
	            if (par1ItemStack.stackSize <= 0)
	            {
	                return new ItemStack(Item.glassBottle);
	            }
	
	            par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.glassBottle));
	        }
	
	        return par1ItemStack;
	    }
	    /**
	     * How long it takes to use or consume an item
	     */
		public int getMaxItemUseDuration(ItemStack par1ItemStack)
	    {
	        return 32;
	    }
	
	    /**
	     * returns the action that specifies what animation to play when the items is being used
	     */
	    public EnumAction getItemUseAction(ItemStack par1ItemStack)
	    {
	        return EnumAction.drink;
	    }
	    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
	    {
	    	 if (!par3EntityPlayer.capabilities.isCreativeMode)
	         {
	             --par1ItemStack.stackSize;
	         }
	
	         par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
	
	         if (!par2World.isRemote)
	         {
	             par2World.spawnEntityInWorld(new EntityPotionMilkSplash(par2World, par3EntityPlayer, par1ItemStack));
	         }
	
	         return par1ItemStack;
	     
	    }
	


	    /**
	     * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
	     * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
	     */
	    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
	    {
	        return false;
	    }

	    @SideOnly(Side.CLIENT)

	    /**
	     * Gets an icon index based on an item's damage value
	     */
	    public Icon getIconFromDamage(int par1)
	    {
	        return isSplash(par1) ? this.field_94591_c : this.field_94590_d;
	    }

	    @SideOnly(Side.CLIENT)

	    /**
	     * Gets an icon index based on an item's damage value and the given render pass
	     */
	    public Icon getIconFromDamageForRenderPass(int par1, int par2)
	    {
	        return par2 == 0 ? this.field_94592_ct : super.getIconFromDamageForRenderPass(par1, par2);
	    }

	    /**
	     * returns wether or not a potion is a throwable splash potion based on damage value
	     */
	    public static boolean isSplash(int par0)
	    {
	        return true;
	    }

	    @SideOnly(Side.CLIENT)
	    public int getColorFromDamage(int par1)
	    {
	    	return 16777215;
	    }

	    @SideOnly(Side.CLIENT)
	    public int getColorFromItemStack(ItemStack par1ItemStack, int par2)
	    {
	        return par2 > 0 ? 16777215 : this.getColorFromDamage(par1ItemStack.getItemDamage());
	    }

	    @SideOnly(Side.CLIENT)
	    public boolean requiresMultipleRenderPasses()
	    {
	        return true;
	    }

	    @SideOnly(Side.CLIENT)
	    public boolean isEffectInstant(int par1)
	    {
	        
	            return true;
	        
	    }


	    @SideOnly(Side.CLIENT)

	    /**
	     * allows items to add custom lines of information to the mouseover description
	     */
	    public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
	    {
	        if (par1ItemStack.getItemDamage() != 0)
	        {
	            List list1 = Item.potion.getEffects(par1ItemStack);

	            if (list1 != null && !list1.isEmpty())
	            {
	                Iterator iterator = list1.iterator();

	                while (iterator.hasNext())
	                {
	                    PotionEffect potioneffect = (PotionEffect)iterator.next();
	                    String s = StatCollector.translateToLocal(potioneffect.getEffectName()).trim();

	                    if (potioneffect.getAmplifier() > 0)
	                    {
	                        s = s + " " + StatCollector.translateToLocal("potion.potency." + potioneffect.getAmplifier()).trim();
	                    }

	                    if (potioneffect.getDuration() > 20)
	                    {
	                        s = s + " (" + Potion.getDurationString(potioneffect) + ")";
	                    }

	                    if (Potion.potionTypes[potioneffect.getPotionID()].isBadEffect())
	                    {
	                        par3List.add(EnumChatFormatting.RED + s);
	                    }
	                    else
	                    {
	                        par3List.add(EnumChatFormatting.GRAY + s);
	                    }
	                }
	            }
	            else
	            {
	                String s1 = StatCollector.translateToLocal("potion.empty").trim();
	                par3List.add(EnumChatFormatting.GRAY + s1);
	            }
	        }
	    }

	    @SideOnly(Side.CLIENT)
	    public boolean hasEffect(ItemStack par1ItemStack)
	    {

	        return true;
	    }



	    

	    @SideOnly(Side.CLIENT)
	    public void registerIcons(IconRegister par1IconRegister)
	    {
	        this.field_94590_d = par1IconRegister.registerIcon("potion");
	        this.field_94591_c = par1IconRegister.registerIcon("potion_splash");
	        this.field_94592_ct = par1IconRegister.registerIcon("potion_contents");
	    }

	    @SideOnly(Side.CLIENT)
	    public static Icon func_94589_d(String par0Str)
	    {
	        return par0Str == "potion" ? Items.itemPotionMilk.field_94590_d : (par0Str == "potion_splash" ? Items.itemPotionMilk.field_94591_c : (par0Str == "potion_contents" ? Items.itemPotionMilk.field_94592_ct : null));
	    }
	}
